package org.soenea.doitall.domain.command;

import org.dsrg.soenea.domain.command.CommandError;
import org.dsrg.soenea.domain.command.CommandException;
import org.dsrg.soenea.domain.command.impl.Command;
import org.dsrg.soenea.domain.helper.Helper;
import org.dsrg.soenea.uow.UoW;
import org.soenea.doitall.domain.model.user.*;
import org.soenea.doitall.domain.model.user.mapper.*;

public class RemoveMemberCommand extends Command {
	public RemoveMemberCommand(Helper helper) {
		super(helper);
	}

	@Override
	public void setUp() throws CommandException {
		// TODO Auto-generated method stub		
	}

	@Override
	public void process() throws CommandException {
		try {
			String id = (String) helper.getRequestAttribute("id");
			if (id != null) { 
				User removedUser = UserInputMapper.find(Long.parseLong(id));
				removedUser.setGroupID(0);
				UoW.getCurrent().registerDirty(removedUser);
				UoW.getCurrent().commit();
			}
    	} catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
    	}
	}

	@Override
	public void tearDown() throws CommandError {
		// TODO Auto-generated method stub
	}
}
